<ion-header>
    <ion-navbar core-back-button>
        <ion-title *ngIf="competency">{{ competency.competency.competency.shortname }} <small>{{ competency.competency.competency.idnumber }}</small></ion-title>
    </ion-navbar>
</ion-header>
<ion-content>
    <ion-refresher [enabled]="competencyLoaded" (ionRefresh)="refreshCompetency($event)">
        <ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
    </ion-refresher>
    <core-loading [hideUntil]="competencyLoaded">
        <ion-card *ngIf="user">
            <ion-item text-wrap>
                <ion-avatar core-user-avatar [user]="user" item-start></ion-avatar>
                <h2>{{ user.fullname }}</h2>
            </ion-item>
        </ion-card>

        <ion-card *ngIf="competency">
            <ion-item text-wrap *ngIf="competency.competency.competency.description">
                <core-format-text [text]="competency.competency.competency.description" [contextLevel]="contextLevel" [contextInstanceId]="contextInstanceId"></core-format-text>
            </ion-item>
            <ion-item text-wrap>
                <strong>{{ 'addon.competency.path' | translate }}</strong>
                <a *ngIf="competency.competency.comppath.showlinks" [href]="competency.competency.comppath.pluginbaseurl + '/competencies.php?competencyframeworkid=' + competency.competency.comppath.framework.id + '&pagecontextid=' + competency.competency.comppath.pagecontextid" core-link [title]="competency.competency.comppath.framework.name">{{ competency.competency.comppath.framework.name }}</a>
                <ng-container *ngIf="!competency.competency.comppath.showlinks">{{ competency.competency.comppath.framework.name }}</ng-container>
                &nbsp;/&nbsp;
                <span *ngFor="let ancestor of competency.competency.comppath.ancestors">
                    <a *ngIf="competency.competency.comppath.showlinks" (click)="openCompetencySummary(ancestor.id)">{{ ancestor.name }}</a>
                    <ng-container *ngIf="!competency.competency.comppath.showlinks">{{ ancestor.name }}</ng-container>
                    <ng-container *ngIf="!ancestor.last">&nbsp;/&nbsp;</ng-container>
                </span>
            </ion-item>
            <ion-item text-wrap>
                <strong>{{ 'addon.competency.crossreferencedcompetencies' | translate }}</strong>:
                <div *ngIf="!competency.competency.hasrelatedcompetencies">{{ 'addon.competency.nocrossreferencedcompetencies' | translate }}</div>
                <div *ngIf="competency.competency.hasrelatedcompetencies">
                    <p *ngFor="let relatedcomp of competency.competency.relatedcompetencies">
                        <a (click)="openCompetencySummary(relatedcomp.id)">
                            {{ relatedcomp.shortname }} - {{ relatedcomp.idnumber }}
                        </a>
                    </p>
                </div>
            </ion-item>
            <ion-item text-wrap *ngIf="coursemodules">
                <strong>{{ 'addon.competency.activities' | translate }}</strong>
                <p *ngIf="coursemodules.length == 0">
                    {{ 'addon.competency.noactivities' | translate }}
                </p>
                <a ion-item text-wrap *ngFor="let activity of coursemodules" [href]="activity.url" [title]="activity.name" core-link capture="true">
                    <img item-start core-external-content [src]="activity.iconurl" alt="" role="presentation" *ngIf="activity.iconurl" class="core-module-icon">
                    <core-format-text [text]="activity.name" contextLevel="module" [contextInstanceId]="activity.id" [courseId]="courseId"></core-format-text>
                </a>
            </ion-item>
            <ion-item text-wrap *ngIf="userCompetency.status">
                <strong>{{ 'addon.competency.reviewstatus' | translate }}</strong>
                {{ userCompetency.statusname }}
            </ion-item>
            <ion-item text-wrap>
                <strong>{{ 'addon.competency.proficient' | translate }}</strong>
                <ion-badge color="success" *ngIf="userCompetency.proficiency">
                    {{ 'core.yes' | translate }}
                </ion-badge>
                <ion-badge color="danger" *ngIf="!userCompetency.proficiency">
                    {{ 'core.no' | translate }}
                </ion-badge>
            </ion-item>
            <ion-item text-wrap>
                <strong>{{ 'addon.competency.rating' | translate }}</strong>
                <ion-badge color="dark">{{ userCompetency.gradename }}</ion-badge>
            </ion-item>
        </ion-card>

        <div *ngIf="competency">
            <h3 margin-horizontal>{{ 'addon.competency.evidence' | translate }}</h3>
            <p margin-horizontal *ngIf="competency.evidence.length == 0">
                {{ 'addon.competency.noevidence' | translate }}
            </p>
            <ion-card *ngFor="let evidence of competency.evidence">
                <a ion-item text-wrap *ngIf="evidence.actionuser" core-user-link [userId]="evidence.actionuser.id" [courseId]="courseId">
                    <ion-avatar core-user-avatar [user]="evidence.actionuser" item-start></ion-avatar>
                    <h2>{{ evidence.actionuser.fullname }}</h2>
                    <p>{{ evidence.timemodified * 1000 | coreFormatDate }}</p>
                </a>
                <ion-item text-wrap>
                    <p><ion-badge color="dark">{{ evidence.gradename }}</ion-badge></p>
                    <p margin-top *ngIf="evidence.description">{{ evidence.description }}</p>
                    <blockquote *ngIf="evidence.note">{{ evidence.note }}</blockquote>
                </ion-item>
            </ion-card>
        </div>
    </core-loading>
</ion-content>
